//
//  ZZPostMenuView.m
//  QQplayground
//
//  Created by zhangxy on 2018/6/14.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "ZZPostMenuView.h"
#import "MyButton.h"
#import "PublishController.h"
#import "PublishPostontroller.h"
#import "PublishMimiController.h"
#import "ZZSignInController.h"

@interface ZZPostMenuView(){
    
}

@property(nonatomic,strong) UIView *supserView;
@property(nonatomic,strong) UIButton *showBtn;
@property(nonatomic,strong) UIViewController *vc;

@end


@implementation ZZPostMenuView

-(instancetype)initWithView:(UIView *)sView vc:(UIViewController *)vc{
    self = [super initWithFrame:CGRectMake(ScreenWidth - 44, NavBarHeight, 44, 0)];
    if (self)
    {
        _supserView = sView;
        _vc = vc;
        self.clipsToBounds = YES;
        self.backgroundColor = UIColorFromRGB(BgTitleColor);
        
        [sView addSubview:self];
        
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dissmisMenu)];
        [self addGestureRecognizer:tap];
        
        
        _showBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_showBtn setImage:[UIImage imageNamed:@"发布21"] forState:0];
        [_showBtn setFrame:CGRectMake(ScreenWidth - 44, StatusBarHeight, 44, 44)];
        _showBtn.tag = 1;
        [_showBtn addTarget:self action:@selector(changeShow:) forControlEvents:UIControlEventTouchUpInside];
        [sView addSubview:_showBtn];
        
        [self createShareButton:1 type:1];
        [self createShareButton:2 type:1];
//        [self createShareButton:3 type:1];
//        [self createShareButton:4 type:1];
    }
    
    return self;
}


-(void)createShareButton:(int) i type:(int) type{
    CGFloat y = 25;
    CGFloat itemW = (SCREEN_WIDTH-40 - 75)/4;
    CGFloat x = 80 + (i-1)*itemW + (i-1)*(ScreenWidth - itemW*2 - 160);
    MyButton *btn = [MyButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:CGRectMake(x, y, itemW, itemW)];
    [btn setTitleColor:DEEP_GRAY_COLOR forState:UIControlStateNormal];
    [btn.titleLabel setFont:ListElevenFont];
    btn.layer.cornerRadius = 15;
    btn.layer.masksToBounds = YES;
    [btn setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(36, 0, 13, 0)];
    [btn addTarget:self action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    
    
        if(i==1){
//            [btn setImage:[UIImage imageNamed:@"素材发布"] forState:UIControlStateNormal];
            [btn setBackgroundImage:[UIImage imageNamed:@"素材发布"] forState:UIControlStateNormal];
            [btn setTitle:@"素材" forState:UIControlStateNormal];
            btn.tag = 1;
        }else if(i==2){
            [btn setBackgroundImage:[UIImage imageNamed:@"帖子发布"] forState:UIControlStateNormal];
            [btn setTitle:@"帖子" forState:UIControlStateNormal];
            btn.tag = 2;
        }else if(i==3){
            [btn setBackgroundImage:[UIImage imageNamed:@"秘密发布"] forState:UIControlStateNormal];
            [btn setTitle:@"秘密" forState:UIControlStateNormal];
//            [btn setImage:[UIImage imageNamed:@"发布 添加图片"] forState:UIControlStateNormal];
//            [btn setTitle:@"QQ好友" forState:UIControlStateNormal];
            btn.tag = 3;
        }else if(i==4){
            [btn setBackgroundImage:[UIImage imageNamed:@"签到发布"] forState:UIControlStateNormal];
            [btn setTitle:@"签到" forState:UIControlStateNormal];
//            [btn setImage:[UIImage imageNamed:@"发布 添加图片"] forState:UIControlStateNormal];
//            [btn setTitle:@"QQ好友" forState:UIControlStateNormal];
            btn.tag = 4;
        }
    
}

-(void)changeShow:(UIButton *)btn{
    if(self.frame.origin.x == 0){
        [self dissmisMenu];
    }else{
        [self show];
    }
}

-(void)actionButton:(MyButton *) shareButton{
    int tag = (int)shareButton.tag;
    // 1素材，2帖子，3秘密，4签到
    
    if(tag == 1){
        // 素材
        PublishController *pvc = [[PublishController alloc] init];
        pvc.type = tag;
        [_vc.navigationController pushViewController:pvc animated:YES];
    }
    if(tag == 2){
        PublishPostontroller *pvc = [[PublishPostontroller alloc] init];
        [_vc.navigationController pushViewController:pvc animated:YES];
    }
    if(tag == 3){
        PublishMimiController *pvc = [[PublishMimiController alloc] init];
        [_vc.navigationController pushViewController:pvc animated:YES];
        
    }
    if(tag == 4){
        ZZSignInController *pvc = [[ZZSignInController alloc] init];
        [_vc.navigationController pushViewController:pvc animated:YES];
        
    }
}


- (void)dissmisMenu{
    if(_displayViews){
        for (UIView *v in _displayViews) {
            v.hidden = NO;
        }
    }
    [UIView animateWithDuration:0.2 animations:^{
        
        self.frame = CGRectMake(ScreenWidth - 44, NavBarHeight, 44, 0);
        self.showBtn.transform =CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
//        [self removeFromSuperview];
    }];
    
}

-(void)show{
    if(_displayViews){
        for (UIView *v in _displayViews) {
            v.hidden = YES;
        }
    }
    
    CGRect sheetViewF = self.frame;
    sheetViewF.origin.x = 0;
    sheetViewF.origin.y = NavBarHeight;
    sheetViewF.size.width = SCREEN_WIDTH;
    sheetViewF.size.height = 130;
    
    
    [UIView animateWithDuration:0.25 animations:^{
        self.frame = sheetViewF;
        //顺时针旋转
        self.showBtn.transform = CGAffineTransformRotate(self.showBtn.transform, M_PI_4);
    } completion:^(BOOL finished) {
        
    }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
